// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <QtCore/QRegExp>

#include "ui/reportgen.h"
#include "probes/probe.h"
#include "ui/support.h"

namespace popdiag {

ReportGenerator::ReportGenerator(QObject *parent)
  : QObject(parent) {
}

QString ReportGenerator::GenerateReport() {
  // TODO: Want a summary in the subject line.  Fault codes
  //       that failed, for example.
  QString payload;
  payload += "<html><head><title>POP and IMAP Troubleshooter Report for "
             + username_;
  payload += "</title></head><body>\n";
  payload += "<font size=-2>";
  payload += "<h3>Mail Reader Configuration</h3>\n";
  payload += config_log_;
  for (int i = 0; i < probes_.size(); ++i) {
    payload += QString("<h3>%1</h3>").arg(names_[i]);
    payload += probes_[i]->DebugText();
  }
  payload += "</font></body></html>";
  return payload;
}

void ReportGenerator::AddProbe(const QString &name, Probe *p) {
  names_.append(name);
  probes_.append(p);
}

}  // namespace popdiag
